package com.cskaoyan.day5.map._03_example;

import java.util.*;

/**
 *
 * 找工作面试用
 * 提升自己
 * 写代码要用
 * @author Common-zhou
 * @since 2023-03-03 16:21
 */
public class Demo3 {
    public static void main(String[] args) {
        // zs   hubei
        // ls   hunan
        // wu  hubei
        // zl   hunan

        // hubei    zs ,wu
        // hunan    ls, zl

        List<Student> list = generateStudents();
        // key是省份
        // value 学生的集合

        Map<String, List<Student>> map = new HashMap<>();

        for (Student student : list) {

            String province = student.province;

            // 现在可能拿到什么东西
            // null       List<Student>
            List<Student> list1 = map.get(province);

            // null
            if (list1 == null) {
                list1 = new ArrayList<>();
            }

            list1.add(student);

            map.put(province, list1);
        }


        Set<String> set = map.keySet();
        for (String province : set) {
            List<Student> list1 = map.get(province);

            System.out.println(province);
            System.out.println(list1);

            System.out.println("======================================");
        }


    }


    private static List<Student> generateStudents() {
        // 空的List   就是装学生的
        List<Student> students = new ArrayList<>();

        List<String> provinceList = Arrays.asList("hubei", "hunan", "guangdong");

        for (int i = 0; i < 50; i++) {
            Student student = new Student();
            student.setName("student" + i);
            student.setAge(15);
            // 从省份的list中，获取出一个省份，设置到学生上
            String province = provinceList.get(i % 3);
            student.setProvince(province);

            students.add(student);
        }

        return students;
    }
}


class Student {
    String name;
    int age;
    String province;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    @Override
    public String toString() {
        return "Student{" + "name='" + name + '\'' + ", age=" + age + ", province='" + province + '\'' + '}';
    }
}
